#include "widget.h"
#include "ui_widget.h"
#include <QTimer>
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //设置初始值
    ui->lcdNumber->display(10);
    //实现每秒钟-1
    QTimer* timer=new QTimer(this);//每次溢出产生一个timeout信号
    timer->start(1000);//单位ms
    connect(timer,&QTimer::timeout,this,[this,&timer]()
    {
        int value=ui->lcdNumber->intValue();
        if(value<=0) timer->stop();
        else ui->lcdNumber->display(value-1);
    });
}

Widget::~Widget()
{
    delete ui;
}

